package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.OmsOrderReturnApply;
import com.macro.mall.model.OmsOrderReturnReason;
import com.macro.mall.portal.domain.OmsOrderDetail;
import com.macro.mall.portal.domain.OmsOrderReturnApplyParam;
import com.macro.mall.portal.service.OmsPortalOrderReturnApplyService;
import com.macro.mall.portal.vo.OmsOrderReturnApplyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 申请退货管理Controller
 * Created by macro on 2020/7/31.
 */
@Controller
@Api(tags = "OmsPortalOrderReturnApplyController", description = "申请退货管理")
@RequestMapping("/returnApply")
public class OmsPortalOrderReturnApplyController {
    @Autowired
    private OmsPortalOrderReturnApplyService returnApplyService;

    @ApiOperation("申请退货")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody OmsOrderReturnApplyParam returnApply) {
        int count = returnApplyService.create(returnApply);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    @ApiOperation("退货原因")
    @RequestMapping(value = "/returnReason/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<OmsOrderReturnReason>> returnReasonList() {
        return CommonResult.success(returnApplyService.returnReasonList());
    }
    @ApiOperation("根据退货ID获取单个退货信息")
    @RequestMapping(value = "/getById/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<OmsOrderReturnApplyVO> getById(@PathVariable Long id) {
        return CommonResult.success(returnApplyService.getById(id));
    }
    @ApiOperation("按状态分页获取用户退货列表")
    @ApiImplicitParam(name = "status", value = "订单状态：0->待处理；1->退货中；2->已完成；3->已拒绝",
            defaultValue = "-1", allowableValues = ",0,1,2,3", paramType = "query", dataType = "int")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<OmsOrderReturnApply>> list(@RequestParam Integer status,
                                                              @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                              @RequestParam(required = false, defaultValue = "5") Integer pageSize) {
        List<OmsOrderReturnApply> orderPage = returnApplyService.list(status,pageNum,pageSize);
        return CommonResult.success(CommonPage.restPage(orderPage));
    }
}
